home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / U-Z / VideoToolBox Folder / VideoToolboxSources / Mean.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-04  |  442 b   |  29 lines  |  [TEXT/KAHL]

  1. /*
  2. Mean.c
  3. Computes mean (and optionally the standard deviation) of an array of samples.
  4.  
  5. HISTORY:
  6. 9/16/90    dgp    wrote it.
  7. */
  8. #include "VideoToolbox.h"
  9. #include <math.h>
  10.  
  11. double Mean(double x[],long n,double *sdPtr)
  12. {
  13.     register double s,mean,xx;
  14.     register long i;
  15.     
  16.     s=0.0;
  17.     for(i=0;i<n;i++) s+=x[i];
  18.     mean=s/n;
  19.     if(sdPtr!=NULL){
  20.         s=0.0;
  21.         for(i=0;i<n;i++){
  22.             xx=x[i];
  23.             s+=xx*xx;
  24.         }
  25.         *sdPtr=sqrt((s-n*mean*mean)/(n-1));
  26.     }
  27.     return mean;
  28. }
  29.